﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Admin.Controls
{
    public partial class AddSlideShow : System.Web.UI.UserControl
    {
        public string filePathSlide;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Banner", "Banner_ID"));
                if (txtLink.Text != "")
                {
                    if (txtTitle.Text != "")
                    {
                        if (fulImageSlide.HasFile)
                        {
                            if (LIB.Validate.CheckFileType(fulImageSlide.FileName))
                            {
                                
                                    int idnextslideshow = nextid + 1;
                                    string linkimage = fulImageSlide.FileName;
                                    LIB.Validate saveimage = new LIB.Validate();
                                    saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Images/Slide-Show/"), linkimage, 940, fulImageSlide.PostedFile.InputStream);
                                    filePathSlide = "/Images/Slide-Show/" + fulImageSlide.FileName;
                                    string value = "" + idnextslideshow + ",N'" + txtName.Text + "','Index','" + filePathSlide + "','" + txtLink.Text + "','" + txtTitle.Text + "','940x400','" + DateTime.Now.ToString() + "'";
                                    List<string> values = new List<string>();
                                    values.Add(value);
                                    DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Banner", "insertemployee", values, false);
                                    Response.Redirect("/Admin/Index.aspx?panel=5&sub=0");                               
                              
                            }
                            else
                            {
                                Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('Bạn vui lòng upload ảnh SlideShow...')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('Vui lòng nhập tên tiêu đề slideshow...')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập link liên kết...')</script>");
                }
            }
            catch (Exception)
            {
                Response.Redirect("/error.htm");
            }           
        }
    }
}